package com.icss.flow.utils;

import com.icss.flow.pojo.entity.TMetaField;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author WZG
 * @date 2024年04月18日 11:51
 */
public class MetaFieldUtils {
    private static final List<String> FIELDS = new ArrayList<>(){{
        add("createdOn");
        add("createdBy");
        add("modifiedOn");
        add("modifiedBy");
        add("ownerUser");
        add("ownerDepartment");
        add("approvalStatus");
        add("flowId");
        add("tenant_id");
    }};
    private static final Integer ID_FIELD_FLAG = 1;

    /***
     * 判断是否是系统默认保留字段
     * @param tMetaField
     * @return
     */
    public static Boolean isReservedField(TMetaField tMetaField) {
        return tMetaField.getIdFieldFlag().equals(ID_FIELD_FLAG)||FIELDS.contains(tMetaField.getPhysicalName());
    }

    /***
     * 获取默认字段FieldList
     * @param entityCode
     * @return
     */
    public static List<TMetaField> getDefualtFieldList(Integer entityCode, String idName) {
        List<TMetaField> fieldList = new ArrayList<>();
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, idName, "id主键", idName, "primaryKey", 0, 1, 0, 1, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "createdOn", "创建时间", "createdOn", "datePicker", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "createdBy", "创建用户", "createdBy", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "modifiedOn", "最近修改时间", "modifiedOn", "datePicker", 0, 1, 0, 0, 0, 0, 0, ""));

        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "modifiedBy", "修改用户", "modifiedBy", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "ownerUser", "所属用户", "ownerUser", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "ownerDepartment", "所属部门", "ownerDepartment", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "approvalStatus", "审批状态", "approvalStatus", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "flowId", "流程id", "flowId", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
                entityCode, "tenant_id", "租户id", "tenant_id", "input", 0, 1, 0, 0, 0, 0, 0, ""));
        return fieldList;

    }
}
